<template>
  <el-card>
    <el-form :inline="true">
      <el-form-item label="一级分类">
        <el-select :disabled="scene == 0 ? false: true" placeholder="请选择" v-model="categoryStore.c1Id" @change="handler" style="width: 220px;">
          <!-- option: label即为显示文字  value属性为select下拉菜单收集属性 -->
          <el-option v-for="(c1, index) in categoryStore.c1Arr" :label="c1.name" :key="c1.id" :value="c1.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select :disabled="scene == 0 ? false: true"  placeholder="请选择" v-model="categoryStore.c2Id" @change="handler1" style="width: 220px;">
          <!-- option: label即为显示文字  value属性为select下拉菜单收集属性 -->
          <el-option v-for="(c2, index) in categoryStore.c2Arr" :label="c2.name" :key="c2.id" :value="c2.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select :disabled="scene == 0 ? false: true"  placeholder="请选择" v-model="categoryStore.c3Id" style="width: 220px;">
          <!-- option: label即为显示文字  value属性为select下拉菜单收集属性 -->
          <el-option v-for="(c3, index) in categoryStore.c3Arr" :label="c3.name" :key="c3.id" :value="c3.id"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>
<script setup lang='ts' name='category'>
import { onMounted } from 'vue';
import useCategoryStore from '@/store/modules/category';
let categoryStore = useCategoryStore()
//分类全局组件挂载完毕，通知仓库发请求获取一级分类的数据
onMounted(() => {
  getC1()
})

const getC1 = () => {
  //通知分类仓库发请求获取一级分类数组
  categoryStore.getC1()
}

//一级分类的change事件（保证一级分类ID有了才找二级分类）
const handler = () => {
  //清空二级三级分类数据
  categoryStore.c2Id=''
  categoryStore.c3Id=''
  categoryStore.c3Arr=[]
  //获取二级分类
  categoryStore.getC2()
}

//一级分类的change事件（保证一级分类ID有了才找二级分类）
const handler1 = () => {
  //清空三级分类数据
  categoryStore.c3Id=''
  //获取三级分类
  categoryStore.getC3()
}
defineProps(['scene'])
</script>


<style scoped></style>